home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / RelativeURL.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  1.2 KB  |  42 lines

  1. package symantec.itools.net;
  2.  
  3.  
  4. import java.net.URL;
  5. import java.net.MalformedURLException;
  6. import symantec.itools.lang.Context;
  7.  
  8.  
  9. //  05/15/97    CAR Added ieAnchorHack to work around an IE problem with anchor symbols in URLs.
  10.  
  11. public class RelativeURL
  12. {
  13.     public static URL getURL(String spec)
  14.         throws MalformedURLException
  15.     {
  16.         
  17.         // InternetExplorer for some reason strips out a single anchor symbol (#) 
  18.         // when the URL is passed to showDocument() so we double up the symbol (##)
  19.         if (System.getProperty("java.vendor").startsWith("Microsoft") && 
  20.             spec.indexOf('#') > -1) {
  21.                 spec = ieAnchorHack(spec);
  22.         }
  23.         
  24.         URL documentBase = Context.getDocumentBase();
  25.  
  26.         if(documentBase != null && spec.indexOf("//") == -1)
  27.         {
  28.             return new URL(documentBase,spec);
  29.         }
  30.  
  31.         return new URL(spec);
  32.     }
  33.     
  34.     private static String ieAnchorHack(String spec) {
  35.         String str = spec.substring(0, spec.lastIndexOf('#'));
  36.         str += "#";
  37.         str += spec.substring(spec.lastIndexOf('#'));
  38.         return str;
  39.     }
  40.         
  41.         
  42. }